home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 240 (DVD) / Issue 240 - February 2008 - DPCS0208DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / Style_Template_English / js / scripts.js < prev   
Encoding:
Text File  |  2007-04-11  |  18.3 KB  |  587 lines

  1. var MODE_DEVELOP = false;
  2. var isObjectSelect = false;
  3. var flashObjectId = "";
  4. var flashObjectIdSelected = -1;
  5. var clickOnObject  = false;
  6.  
  7. var bannerColl = typeof(NOF) != "undefined" ? NOF.Flash.MovieCollectionMgr.createCollection() : null;
  8. var navbarColl = typeof(NOF) != "undefined" ? NOF.Flash.MovieCollectionMgr.createCollection() : null;
  9.  
  10. /***
  11. * event listener for flash objects
  12. ***/
  13. function NOF_Flash_Listener(fId, oId, pId) {
  14.   var method = NOF_Flash_Listener.prototype;
  15.  
  16.   this.objectId = oId;
  17.   this.parentId = pId;
  18.   this.flashId = fId;
  19.  
  20.   method.onRMouseDown = function (event) {
  21.   var elem = document.getElementById(this.objectId);
  22.     if (this.parentId == -1) {
  23.       NOF_StyleView_CallInspector(elem, 'graphic', "", event.state.x, event.state.y);
  24.     }
  25.     else {
  26.       var flashObject = document.getElementById(this.parentId);
  27.       NOF_StyleView_CallFlashInspector(elem, flashObject, 'graphic', "", event.state.x, event.state.y);
  28.     }
  29.   };
  30.  
  31.   method.onDblClick = function (event) {
  32.   if (this.parentId == -1) {
  33.       var elem = document.getElementById(this.objectId);
  34.       NOF_StyleView_DblClick(elem, "graphic");
  35.     }
  36.     else {
  37.       var flashObject = document.getElementById(this.parentId);
  38.       NOF_StyleView_DblClickEx(flashObject, "graphic", true) ;
  39.     }
  40.  
  41.   };
  42.  
  43.   method.onLMouseDown = function (event) {
  44.     var elem = document.getElementById(this.objectId);
  45.     if (this.parentId == -1) {
  46.     NOF_StyleView_CallInspector(elem, 'graphic');
  47.     }
  48.     else {
  49.       var flashObject = document.getElementById(this.parentId);
  50.     NOF_StyleView_CallFlashInspector(elem, flashObject, 'graphic');
  51.     }
  52.   };
  53.  
  54.   method.onMouseDown = function (event) {
  55.     flashObjectId = this.flashId;
  56.     if (event.state.btn == 2) {
  57.       this.onRMouseDown(event);
  58.     }
  59.     else if (event.state.cnt == 2) {
  60.       this.onDblClick(event);
  61.     }
  62.     else {
  63.       this.onLMouseDown(event);
  64.     }
  65.     clickOnObject = false;
  66.   };
  67. }
  68.  
  69.  
  70. /**
  71. *Called from c++ layer on page load. must be removed.
  72. */
  73. function SelectObject(object, inspectorType){
  74.   NOF_StyleView_CallInspector(document.getElementById(object), inspectorType);
  75. }
  76.  
  77. function NOF_StyleView_CallFlashInspector(object, flashObject, inspectorType, objectParent, x, y) {
  78.     flashObjectIdSelected = object.id;
  79.     NOF_StyleView_CallInspector(flashObject, inspectorType, objectParent, x, y);
  80.     if (flashObject.id != object.id) {
  81.         object.className = "objSelected";
  82.         flashObject.className = "objNormal";
  83.     }
  84. }
  85.  
  86. function NOF_StyleView_CallInspector(object, inspectorType, objectParent, x, y) {
  87.   clearBorder();
  88.  
  89.   // Check if fusion is available
  90.   if (fusion == null || typeof(fusion) == "undefined")
  91.     return;
  92.  
  93.   isObjectSelect = false;
  94.  
  95.   if(object) {
  96.     isObjectSelect = true;
  97.     clickOnObject  = true;
  98.  
  99.     if (object.className == "objNormal")
  100.       object.className = "objSelected";
  101.  
  102.     var response = null;
  103.  
  104.     // In case there is right click on body and a different context menu is displayed.
  105.     var id = object.id ? object.id : "context";
  106.  
  107.     // Inspector call
  108.     response = inspectorType == "text" && inspectorType != null ?
  109.                ( x && y ? fusion.onTextStyleSelected(id  + ":" + x + ":" + y) : fusion.onTextStyleSelected(id)) :
  110.                 ( x && y ? fusion.onGraphicStyleSelected(id  + ":" + x + ":" + y) : fusion.onGraphicStyleSelected(id))
  111.  
  112.   } else {
  113.      if (!clickOnObject && !MODE_DEVELOP) {
  114.        clearBorder();
  115.        inspectorType == "text" ? fusion.onTextStyleSelected("NULL") : fusion.onGraphicStyleSelected("NULL");
  116.      } else
  117.        clickOnObject = false;
  118.   }
  119. }
  120.  
  121. function NOF_StyleView_DblClick(object, inspectorType) {
  122.   NOF_StyleView_DblClickEx(object, inspectorType, false);
  123. }
  124.  
  125. function NOF_StyleView_DblClickEx(object, inspectorType, isParentSelected) {
  126.   // Check if fusion is available
  127.   if (fusion == null || typeof(fusion) == "undefined")
  128.     return;
  129.   if (object.id && inspectorType == "graphic") {
  130.     /*
  131.       isParentSelected : true if flash navigation selected
  132.       object.className = "objNormal" : (not selected) happens when
  133.       the click following a flash double click triggers a double click
  134.       event instead of a single click. See CStyleGraphicView::PreTranslateMessage
  135.     */
  136.     if (!isParentSelected && object.className == "objNormal") {
  137.       flashObjectId = "";
  138.       NOF_StyleView_CallInspector(object, inspectorType);
  139.       clickOnObject  = false;
  140.     }
  141.     else
  142.       fusion.onGraphicStyleDblClick(object.id);
  143.   }
  144. }
  145.  
  146. function NOF_StyleView_ResponseFromInspector(xmlNodeText) {
  147.   var xmlNode = new ActiveXObject("Msxml2.DOMDocument.3.0");
  148.   xmlNode.async = false;
  149.   if (typeof(xmlNodeText) == "string")
  150.     xmlNode.loadXML(xmlNodeText);
  151.   else
  152.     xmlNode = xmlNodeText;
  153.  
  154.   var xslt = new ActiveXObject("Msxml2.DOMDocument.3.0");
  155.   xslt.async = false;
  156.   xslt.load("template/siteStyle.xsl");
  157.  
  158.   var root = xmlNode.documentElement;
  159.   var rootName = root.nodeName;
  160.  
  161.   var refreshString = "";
  162.   if (rootName == "Banner") {
  163.     if (root.getAttribute("type") == "Flash") {
  164.       var flashNode = root.selectSingleNode("Flash");
  165.       onChangeFlashBanner(root.getAttribute("id"), root.getAttribute("name"), flashNode.getAttribute("path"));
  166.     }
  167.   else {
  168.       refreshString = xmlNode.transformNode(xslt);
  169.       onChangeBanner(root.getAttribute("id"), refreshString);
  170.   }
  171.   }
  172.   else if (rootName == "ButtonState") {
  173.     if (root.getAttribute("type") == "Flash") {
  174.       var flashNode = root.selectSingleNode("Flash");
  175.       onChangeFlashNavBarState(root.getAttribute("id"), root.getAttribute("name"), flashNode.getAttribute("path"));
  176.     }
  177.     else {
  178.       refreshString = xmlNode.transformNode(xslt);
  179.       if (root.getAttribute("type") == "Text") {
  180.           onChangeButtonState(root.getAttribute("id"), refreshString);
  181.           document.styleSheets["displaycss"].href="display.css?dummy="+(new Date()).getTime(); //force reload display.css
  182.           var id = root.getAttribute("id");
  183.       var selector = "." + root.selectSingleNode("Font").getAttribute("css");
  184.       document.getElementById(id).style.cssText = getCssContent(selector);
  185.           return;
  186.       }
  187.       else if (root.getAttribute("type") == "Image") {
  188.         onChangeButtonState(root.getAttribute("id"), refreshString, root.selectSingleNode("Image").getAttribute("path"));
  189.       }
  190.     }
  191.   }
  192.   else if (rootName == "Line") {
  193.     refreshString = xmlNode.transformNode(xslt);
  194.     onChangeLine(root.getAttribute("id") , refreshString);
  195.   }
  196.   else if (rootName == "Bullet") {
  197.     refreshString = xmlNode.transformNode(xslt);
  198.     onChangeBullet(root.getAttribute("id"), refreshString);
  199.   }
  200.   else if (rootName == "NavbarState") {
  201.     if (root.getAttribute("type") == "Flash") {
  202.       var button = root.selectSingleNode("Button");
  203.       var buttonState = button.selectSingleNode("ButtonState");
  204.       var flashNode = buttonState.selectSingleNode("Flash");
  205.       onChangeFlashNavBarState(root.getAttribute("id"), root.getAttribute("name"), flashNode.getAttribute("path"));
  206.     }
  207.     else {
  208.       var border = root.selectSingleNode("Border").getAttribute("size");
  209.       var space  = root.selectSingleNode("Space").getAttribute("size");
  210.       onChangeNavbarState(root.getAttribute("id"), border, space, root.getAttribute("name"));
  211.     }
  212.   }
  213.   else if (rootName == "Author") {
  214.     refreshString = xmlNode.transformNode(xslt);
  215.     onChangeAuthor(root.getAttribute("id"), refreshString);
  216.   }
  217.   else if (rootName == "TableStyle") {
  218.     refreshString = xmlNode.transformNode(xslt);
  219.     onChangeTableStyle(root.getAttribute("id") , refreshString);
  220.   }
  221.   //Refresh : called when background is change; or text fonts
  222.   else if (rootName == "SiteStyle") {
  223.     onRefreshPage();
  224.   }
  225.   else //text
  226.   {
  227.     document.styleSheets["displaycss"].href="display.css?dummy="+(new Date()).getTime(); //force reload display.css
  228.     refreshString = xmlNode.transformNode(xslt);
  229.     document.getElementById(root.getAttribute("id")).outerHTML = refreshString;    
  230.     document.getElementById(root.getAttribute("id")).className = "objSelected";
  231.   }
  232.   if (typeof(NOF) != "undefined") {
  233.     navbarColl.resizeAll();
  234.   }
  235. }
  236.  
  237. function refreshImages(imageId) {
  238.     var len = document.all.length;
  239.     for (var i=0;i<len;i++) {
  240.       var pNode = document.all[i];
  241.       var idObj = pNode.attributes.id;
  242.       if (idObj != null) {
  243.         var id = idObj.value;
  244.         if (id != null)
  245.         {
  246.           if (id == imageId) {
  247.             if (pNode.attributes.src != null)
  248.             {
  249.               var src = pNode.src;
  250.               var d = new Date();
  251.               var time = d.getTime();
  252.               pNode.src = src + "?" + time;
  253.             }
  254.           }
  255.         }
  256.       }
  257.     }
  258. }
  259.  
  260. //Event handlers
  261.  
  262. function onChangeBanner(bannerId, value){
  263.   document.getElementById("Banner." + bannerId).innerHTML = value
  264.   //document.getElementById(bannerId).innerHTML = value;
  265.   document.getElementById(bannerId).className = "objSelected";
  266.   refreshImages(bannerId);
  267. }
  268.  
  269. function onChangeFlashBanner(flashId, bannerName, bannerSrc) {
  270.   document.getElementById("BannerLabel." + flashId).innerHTML = bannerName;
  271.   var banner = bannerColl.getMovieById("Banner_Flash_"+flashId);
  272.   if (banner) {
  273.       banner.setMovieSrc(bannerSrc);
  274.       document.getElementById(flashId).innerHTML = banner.toHTML();
  275.     }
  276.     document.getElementById(flashId).className = "objSelected";
  277. }
  278.  
  279. function onChangeButtonState(buttonStateId, value, buttonSrc) {
  280.   document.getElementById("Button." + buttonStateId).innerHTML = value;
  281.   document.getElementById(buttonStateId).className = "objSelected";
  282.   refreshImages(buttonStateId);
  283. }
  284.  
  285. function onChangeLine(lineId, value){
  286.   document.getElementById(lineId).className = "objSelected";
  287.   document.getElementById(lineId).innerHTML = value;
  288. }
  289.  
  290. function onChangeBullet(bulletId, value) {
  291.   document.getElementById(bulletId).className = "objSelected";
  292.   document.getElementById(bulletId).innerHTML = value;
  293. }
  294.  
  295. function onRefreshPage() {
  296.   document.location.href = "Style.ssx";
  297. }
  298.  
  299. function onChangeNavbarState(navbarStateId, borderValue, spacingValue, navName){
  300.   document.getElementById(navbarStateId).className = "objSelected";
  301.   document.getElementById(navbarStateId).innerHTML = navName;
  302.   document.getElementById("NavbarState." + navbarStateId).border       = borderValue;
  303.   document.getElementById("NavbarState." + navbarStateId).cellPadding  = spacingValue;
  304.   document.getElementById("NavbarState." + navbarStateId).cellSpacing  = spacingValue;
  305. }
  306.  
  307. function onChangeFlashNavBarState(flashId, navName, navbarSrc) {
  308.   if (navbarColl.getMovieById("Button_Flash_F_"+flashId)) {
  309.     /*@note: workaround for innerHTML replace below that cause the dynamic dinamic
  310.              dimension setting to have no effect.
  311.     */
  312.     var MAX_WIDTH = 1000;
  313.  
  314.     var bf = navbarColl.getMovieById("Button_Flash_F_"+flashId);
  315.     bf.setMovieSrc(navbarSrc);
  316.     bf.setParam("play", "true");
  317.     bf.setWidth(MAX_WIDTH);
  318.     document.getElementById("Button_Flash_F_"+flashId+"_container").innerHTML = bf.toHTML();
  319.  
  320.     var bp = navbarColl.getMovieById("Button_Flash_P_"+flashId);
  321.     bp.setWidth(MAX_WIDTH);
  322.     bp.setMovieSrc(navbarSrc);
  323.     bp.setParam("play", "true");
  324.     document.getElementById("Button_Flash_P_"+flashId+"_container").innerHTML = bp.toHTML();
  325.   }
  326.   else {
  327.     document.getElementById(flashId).innerHTML = navName;
  328.   }
  329.   document.getElementById(flashObjectIdSelected).className = "objSelected";
  330. }
  331.  
  332. function onChangeAuthor(id, newName) {
  333.  
  334.   var searchText = '<font class="label">';
  335.   var author = newName.substring(newName.indexOf(searchText) + searchText.length, newName.length);
  336.   author = author.substring(0, author.indexOf('</font>'));
  337.  
  338.   handleAuthor(id, author);
  339. }
  340.  
  341. function handleAuthor(id, author) {
  342.  
  343.   var htmlObj = document.getElementById(id);
  344.   if (author == null) {
  345.    author = htmlObj.innerHTML;
  346.    onChangeAuthor(id, author);
  347.   }
  348.  
  349.  
  350.   var authorURL = "";
  351.   var protocol = "";
  352.   var authorName = author;
  353.   var urlCaption = "";
  354.  
  355.   var indexOfStartURL = author.indexOf("(");
  356.   if (indexOfStartURL >= 0) {
  357.   var indexOfEndURL = author.lastIndexOf(")");
  358.   if (indexOfEndURL > 0 && indexOfEndURL > indexOfStartURL) {
  359.     authorURL = author.substring(indexOfStartURL + 1, indexOfEndURL);
  360.     if (authorURL.indexOf("http://") < 0)
  361.       protocol = "http://"
  362.  
  363.     urlCaption = author.substring(indexOfStartURL, indexOfEndURL + 1);
  364.   }
  365.  
  366.   }
  367.  
  368.  
  369.   var html = author;
  370.   if (authorURL != "") {
  371.   html =  '<a href="' + protocol + authorURL + '" target="_blank" class="label" style="text-decoration:none">' + urlCaption + '</a>';
  372.   var leftPos = author.indexOf(urlCaption);
  373.   var rightPos = leftPos + urlCaption.length;
  374.   html = author.substring(0, leftPos) + html + author.substring(rightPos, author.length)
  375.   }
  376.  
  377.  
  378.   htmlObj.innerHTML = '<font class="label">' +  html + '</font>';
  379.   htmlObj.className = "objSelected";
  380. }
  381.  
  382. function onChangeTableStyle(tableStyleId, value){
  383.   document.getElementById(tableStyleId).className = "objSelected";
  384.   document.getElementById(tableStyleId).innerHTML = value;
  385. }
  386.  
  387.  
  388. /**
  389. * Rollover image from navigation bar previews
  390. */
  391. function rollImage(object, isOut) {
  392.   if (object.src){ //image buttons
  393.     if (isOut)
  394.       object.src = object.rollOut;
  395.     else
  396.       object.src = object.roll;
  397.   } else { //text buttons
  398.   var spanAlign = object.className.indexOf('Left') ? 'spanLeft' : (object.className.indexOf('Right') ? 'spanRight' : 'spanCenter');
  399.     if (isOut) {
  400.       object.className = object.rollOut;
  401.     if (object.hasChildNodes()) {
  402.       var childs = object.childNodes;
  403.       if (childs) {
  404.         if (childs.item(0) && childs.item(0).className) {
  405.           childs.item(0).className = spanAlign + object.rollOut;
  406.         }
  407.       }
  408.     }
  409.     } else {
  410.       object.className = object.roll;
  411.     if (object.hasChildNodes()) {
  412.       var childs = object.childNodes;
  413.       if (childs) {
  414.         if (childs.item(0) && childs.item(0).className) {
  415.           childs.item(0).className = spanAlign + object.roll;
  416.         }
  417.       }
  418.     }
  419.     }
  420.   }
  421. }
  422.  
  423.  
  424. /**
  425. *Removes black border arround last selected item
  426. */
  427. function clearBorder() {
  428.   if (isObjectSelect)
  429.     return;
  430.  
  431.   //divs
  432.   var divList = document.getElementsByTagName("div");
  433.   for (var i = divList.length - 1; i >= 0; i--)
  434.     if (divList.item(i).className == "objSelected")
  435.       divList.item(i).className = "objNormal";
  436.  
  437.   //tables
  438.   var tableList = document.getElementsByTagName("table");
  439.   for (var i = tableList.length - 1; i >= 0; i--)
  440.     if (tableList.item(i).className == "objSelected")
  441.       tableList.item(i).className = "";
  442. }
  443.  
  444. document.onmousedown = callMouseDown;
  445.  
  446. var isRightClick = false;
  447. var offsetX = 0, offsetY = 0;
  448.  
  449. function NOF_StyleView_TsRightClick(id) {
  450.   if (event.button == 2 || event.button == 3) {
  451.     isObjectSelect = false;
  452.       offsetX = event.clientX;
  453.       offsetY = event.clientY;
  454.     NOF_StyleView_CallInspector(document.getElementById(id), "graphic", "", offsetX, offsetY)
  455.     event.cancelBubble = true;
  456.     return false;
  457.   }
  458. }
  459.  
  460. function NOF_CallDoubleClick(x,y) {
  461.     //Flash objects events are handled via NOF_Flash_Listener
  462.     // and only flash objects double click have no event defined
  463.     if (event == null && flashObjectId.length > 0)
  464.     {
  465.       notifyMovieEx(1, 2, x, y, flashObjectId);
  466.       flashObjectId = "";
  467.       return true;
  468.   }
  469.   return false;
  470. }
  471.  
  472. function callMouseDown() {
  473.   if (event.button != 1) {
  474.     callContextMenu();
  475.   }
  476.   else {
  477.       isObjectSelect = false;
  478.     isRightClick = false;
  479.     if (isFlashObjectClicked()) {
  480.       notifyMovie(1, 1);
  481.     }
  482.     else {
  483.        flashObjectId = "";
  484.     }
  485.   }
  486. }
  487.  
  488. function callContextMenu(e) {
  489.   isObjectSelect = false;
  490.   if (event.button == 2 || event.button == 3) {
  491.     isRightClick = true;
  492.     offsetX = event.clientX;
  493.     offsetY = event.clientY;
  494.  
  495.     //if click on navbars preview
  496.     if (event.srcElement.name && event.srcElement.name == "modePreview")
  497.       return;
  498.  
  499.     if (event.srcElement.className == "title")
  500.       return;
  501.  
  502.     //Flash objects events are handled via NOF_Flash_Listener
  503.     if (isFlashObjectClicked())
  504.     {
  505.       notifyMovie(2, 1);
  506.       return false;
  507.     }
  508.  
  509.     flashObjectId = "";
  510.  
  511.     //Tab type : 'graphic' or 'text'
  512.     var tabType = (event.srcElement.type == "text") ? "text" : "graphic";
  513.     if (event.srcElement.id && tabType != "text") {
  514.       NOF_StyleView_CallInspector(document.getElementById(event.srcElement.id), tabType, "", offsetX, offsetY)
  515.     } else //Call when right-click on body and not on valid style part.
  516.       NOF_StyleView_CallInspector(-1, tabType, "", offsetX, offsetY)
  517.  
  518.   }
  519.   else
  520.     isRightClick = false;
  521. }
  522.  
  523. function isFlashObjectClicked() {
  524.     if (event.srcElement.tagName == "OBJECT" ||
  525.       event.srcElement.classid == "CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000" ||
  526.       event.srcElement.classid == "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000")
  527.       return true;
  528.   return false;
  529. }
  530.  
  531. function disableFlashEventPropagation() {
  532.   if (event != null) {
  533.     event.cancelBubble = true;
  534.   }
  535.   alert("");
  536. }
  537.  
  538. function notifyMovie(btn, cnt) {
  539.   var x = event.clientX;
  540.   var y = event.clientY;
  541.   var name = event.srcElement.id;
  542.   notifyMovieEx(btn, cnt, x, y, name);
  543. }
  544.  
  545. function notifyMovieEx(btn, cnt, x, y, name) {
  546.   var movie = null;
  547.   var coll = getMovieCollection(name);
  548.   if ((typeof(NOF) != "undefined") && coll != null) {
  549.     movie = coll.getMovieById(name);
  550.     movie.onMouseDown(x,y,btn,cnt);
  551.   }
  552.   disableFlashEventPropagation();
  553. }
  554.  
  555. function getMovieCollection(name) {
  556.   var coll = null;
  557.   var bannerName = new String("Banner_Flash");
  558.   var prefix = name.substring(0,bannerName.length);
  559.   if (prefix == bannerName) {
  560.     coll = bannerColl;
  561.   }
  562.   else {
  563.     var previewName = new String("Button_Flash_P_");
  564.     prefix = name.substring(0, previewName.length);
  565.     if ((prefix != previewName) || (event != null && event.button == 1)) {
  566.       coll = navbarColl;
  567.     }
  568.   }
  569.   return coll;
  570. }
  571.  
  572. function getCssContent(cssClass)
  573. {
  574.     //log(cssClass);
  575.     for (i=0; i<document.styleSheets["displaycss"].rules.length; i++)
  576.     {
  577.         if (document.styleSheets["displaycss"].rules(i).selectorText == cssClass)
  578.             return document.styleSheets["displaycss"].rules(i).style.cssText;
  579.     }
  580. }
  581.  
  582.  
  583. /*
  584. function trace(string){
  585.   document.getElementById("debug").value = document.getElementById("debug").value + "\n" + string;
  586. }*/
  587.